﻿using AdminStyem.Application.Command.traceabilityCommand;
using AdminStyem.Application.DTO;
using AdminStyem.Domain.Entity;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.traceabilityCommandHandler
{
    public class CommodityCommandHandler : IRequestHandler<CommodityCommand, APIResult<List<Commodity>>>
    {
        IBaseRespository<Commodity> BaseCommodity;

        public CommodityCommandHandler(IBaseRespository<Commodity> baseCommodity)
        {
            BaseCommodity = baseCommodity;
        }

        public async Task<APIResult<List<Commodity>>> Handle(CommodityCommand request, CancellationToken cancellationToken)
        {
         APIResult<List<Commodity>> ret= new APIResult<List<Commodity>>();
            ret.Code = ResultCode.查询成功;
            ret.Message = ResultCode.查询成功.ToString();

            var list = await BaseCommodity.GetAll();
            ret.Data = list.ToList();

            return await Task.FromResult(ret);

        }
    }
}
